<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/html">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title>管理后台</title>
    <link rel="stylesheet/less" href="../../../static/css/index.less"/>
    <link rel="stylesheet" href="../../../static/layui/css/layui.css"/>
    <link rel="stylesheet" href="../../../static/css/jquery.pagination.css"/>
    <script src="../../../static/js/jquery-1.12.3.js"></script>
    <script src="../../../static/js/less.min.js"></script>
    <script src="../../../static/layui/layui.js"></script>
    <script src="../../../static/js/ajaxfileupload.js"></script>
    <script src="../../../static/layer/layer.js"></script>
    <SCRIPT language=javascript src="../../static/layer/layer.js"></SCRIPT>
</head>
<style>
    #test1 {
        display: inline-block;
        width: 15%;
    }
</style>
<body class="layui-layout-body">

{% include "/admin/top.html" %}
{% include "/admin/left.html" %}

<div id="box" class="fl">
    <div class="content" style="height: 100%">
        <h3 style="color:  #3D89CB">商家套餐列表</h3>
        <div class="search">

 <button class="s_button clearfix"
                    style="color: white;background-color: #3D89CB;margin-right: 100px ;float: right"
                    onclick='location.href="/admin/suit/newly.html"'>新增商家套餐</button>
        </div>
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <thead>
            <tr>
                <th width="8%">套餐名</th>
                <th>价格</th>
                <th>次数</th>
                <th>是否限购</th>
                <th>排序</th>
                <th width="15%">新增时间</th>
                <th>状态</th>
                <th>操作</th>

            </tr>
            </thead>
            <tbody id="content">

                {% if res %}
                    {% for data in res %}
                         <tr>
                        <td>{{ data.name }}</td>
                        <td>{{ data.price }}</td>
                        <td>{{ data.num }}</td>
                         <td>{% if data.ones == 0 %}不限购{% else %}限购{% endif %}</td>
                         <td>{{ data.weight }}</td>
                         <td>{{ data.add_time }}</td>
                        <td>{% if data.status==1 %}
                            激活
                        {% else %}
                            禁用
                        {% endif %}
                        </td>
                        <td>
                                <button><span style="color: green"><a
                                        href="/admin/suit/edit.html?suit_id={{ data.suit_id }}">编辑</a></span>
                                </button>
                                {% if data.status == 0 %}
                                    <button class="ccc">
                                        <a href="#" onclick="start({{ data.suit_id }})">启用</a>
                                    </button>
                                {% elif data.status == 1 %}
                                    <button class="green">
                                        <a href="#" onclick="stop({{ data.suit_id }})">禁用</a>
                                    </button>
                                {% endif %}
                        <button class="red">
                                        <a href="#" onclick="delete_suit({{ data.suit_id }})">删除</a>
                                    </button>
                            </td>
                        </tr>
                    {% endfor %}
                {% else %}
                    <tr></tr><td colspan=8 align="center">暂无数据</td></tr>
                {% endif %}

            </tr>
            </tbody>
        </table>
        <div id="page" class="ui-pagination-container">
        </div>
    </div>
</div>
</div>
<input type="hidden" value="1" id="p">
</body>
</html>
<script>
    layui.use('laydate', function () {
        var laydate = layui.laydate;
        //执行一个laydate实例
        laydate.render({
            elem: '#test1', //指定元素
        });
    });

     function stop(suit_id) {
        layer.open({
            content: '你确定禁用',
            btn: ['确认', '取消'],
            shadeClose: false,
            yes: function () {
                $.ajax({
                    url: '/admin/suit/stop',
                    type: 'post',
                    data: {
                        'suitId': suit_id
                    },
                    dataType: 'json',
                    success: function (msg) {
                        if (msg.status == 1) {
                            layer.msg("操作成功！", {time: 2000}, function () {
                                window.location.href = "/admin/business/suit.html";
                            });


                        } else {
                            layer.msg("操作失败！");
                        }
                    }
                });
            }
        });
    }
    function start(suit_id) {
        layer.open({
            content: '你确定激活',
            btn: ['确认', '取消'],
            shadeClose: false,
            yes: function () {
                $.ajax({
                    url: '/admin/suit/start',
                    type: 'post',
                    data: {
                        'suitId': suit_id
                    },
                    dataType: 'json',
                    success: function (msg) {
                        if (msg.status == 1) {
                            layer.msg("操作成功！", {time: 2000}, function () {
                           window.location.href = "/admin/business/suit.html";
                            });


                        } else {
                            layer.msg("操作失败！");
                        }
                    }
                });
            }
        });
    }
function delete_suit(suit_id) {
        layer.open({
            content: '你确定删除',
            btn: ['确认', '取消'],
            shadeClose: false,
            yes: function () {
                $.ajax({
                    url: '/admin/suit/delete',
                    type: 'post',
                    data: {
                        'suitId': suit_id
                    },
                    dataType: 'json',
                    success: function (msg) {
                        if (msg.status == 1) {
                            layer.msg("操作成功！", {time: 2000}, function () {
                                window.location.href = "/admin/business/suit.html";
                            });


                        } else {
                            layer.msg("操作失败！");
                        }
                    }
                });
            }
        });
    }
</script>
